package com.qa.controller.admin;

import com.qa.dto.QuestionEditDTO;
import com.qa.entity.Question;
import com.qa.result.Result;
import com.qa.service.QuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "管理端题目接口")
@Slf4j
@RestController
@RequestMapping("/admin/questions")
public class AdminQuestionController {

    @Autowired
    private QuestionService questionService;

    @PutMapping("/edit")
    @ApiOperation(value = "修改题目")
    @PreAuthorize("hasAuthority('authority_admin')")
    public Result editQuestion(@RequestBody QuestionEditDTO questionEditDTO) {
        Question question = new Question();
        BeanUtils.copyProperties(questionEditDTO,question);
        return questionService.editQuestion(question);
    }

}
